<meta title="新增选品库" width="1000" args="itemSelection"/>
<style>
</style>
<form s="valid,form,datac,nda"
      method="put"
      s-data="itemSelection"
      action="/api/itemSelection/{itemSelection.id}"
      id="form" class="form-horizontal">
    <table class="table table-bordered table-hover table-striped">
        <tr>
            <td>名称</td>
            <td>
                <input autocomplete="off" type="text" name="name" style="width: 300px;" id="name" s-valid-error="require()" class="form-control" placeholder="名称">
            </td>
        </tr>
        <tr>
            <td>源选品库</td>
            <td>
                <select class="form-control" id="source" s-change="sourceChange(this)" s="select"
                        s-valid-error="require()"
                        s-build="S.get('/api/tbk-api/favorites')"
                        s-select="{title: titleFn, value: valFn}" name="sourceSelectionId">
                </select>
            </td>
        </tr>
        <tr>
            <td>频道</td>
            <td>
                <select class="form-control" s="select" s-build="S.get('/api/channel/list')" name="channelId">
                    <option value="">不选频道</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>类目</td>
            <td>
                <input autocomplete="off" type="text" name="shopcatId" readonly class="form-control" s s-click="selectShopcat(this)"/>
            </td>
        </tr>
        <tr>
            <td>优选</td>
            <td>
                <label class="s-checkbox-switch">
                    <input autocomplete="off" type="checkbox" name="recommend" value="true" />
                    <span class="s-checkbox-indicator"></span>
                </label>
            </td>
        </tr>
        <tr>
            <td>抓取链接</td>
            <td>
                <input autocomplete="off" type="text" name="fetchUrl" class="form-control" />
            </td>
        </tr>
        <tr>
            <td>抓取页数</td>
            <td>
                <input autocomplete="off" type="number" name="maxPage" min="1" s-valid-error="require(),number()" class="form-control" />
            </td>
        </tr>
        <tr>
            <td>自动抓取</td>
            <td>
                <label class="s-checkbox-switch">
                    <input autocomplete="off" type="checkbox" name="autoFetch" value="true" />
                    <span class="s-checkbox-indicator"></span>
                </label>
            </td>
        </tr>
        <tr>
            <td>状态</td>
            <td>
                <select class="form-control" s="select"
                        name="status"
                        s-build="S.get('/api/enum/valuesMap/core.enums.ItemSelectionStatus?igNames=DELETED')">
                </select>
            </td>
        </tr>
    </table>
</form>
<script>
    S.meta.btns = [
        {
            name: "确定",
            style: "btn btn-primary",
            click: function() {
                return $form.submit().done(function() {
                    S.close(true)
                })
            }
        },
        {
            name: "关闭",
            style: "btn btn-default",
            click: function() {
                S.close();
            }
        }
    ]

    function titleFn(obj) {
        return obj.favoritesTitle + (obj.type === 2 ? " - 高佣" : '');
    }

    function valFn(obj) {
        return obj.favoritesId
    }

    function sourceChange($this) {
        // var data = $this.getSelectData();
        // $name.node.val(data && data.favoritesTitle);
    }

    S.on("s-ready", function() {
        $source.node.change();
    })

    function selectShopcat($this) {
        S.popupOpen("/shopcat/shopcatSelector.html").done(function(id) {
            id && $this.node.val(id);
        })
    }

</script>